package gotlib

import (
	"gitee.com/tommickey/gose/v3/internal/app/common/global"
	"github.com/gogf/gf/v2/frame/g"
)

// ConfigEngineAddUserParams 把当前用户信息合并到参数里。以 CurrentCtxUser 开头
func ConfigEngineAddUserParams(Params g.MapStrStr, user g.MapStrStr) g.MapStrStr {
	Params["CurrentUserId"] = user["id"]
	Params["CurrentUserName"] = user["userName"]
	Params["CurrentUserDeptId"] = user["deptId"]
	Params["CurrentUserNickname"] = user["userNickname"]
	Params["CurrentUserStatus"] = user["userStatus"]
	Params["CurrentUserIsBack"] = user["isAdmin"]

	return Params
}

// SysConfigEngineAddUserParams 把当前用户信息合并到参数里。以 CurrentCtxUser 开头
func SysConfigEngineAddUserParams(Params g.MapStrStr, user g.MapStrStr) g.MapStrStr {
	if Params == nil {
		Params = g.MapStrStr{}
	}
	for k, v := range user {
		Params[StrJoin("", global.SysConfigEngineCurrentCtxUser, StrFirstUpper(k))] = v
	}
	return Params
}

/*
// GetCacheString 获取cache内容=>改到gotcache库中
func GetCacheString(cacheKey string) (value string, err error) {
	//cacheKey := strings.Join([]string{key, "-", gconv.String(userId)}, "")
	cacheMode := g.Cfg().GetInt8("gToken.system.CacheMode")
	switch cacheMode {
	case gtoken.CacheModeCache:
		cacheValue, err := gcache.Get(cacheKey)
		return String(cacheValue), err
	case gtoken.CacheModeRedis:
		cacheValue, err := g.Redis().Do("GET", cacheKey)
		if err != nil {
			g.Log().Error("[GToken]cache get error", err)
		}
		if cacheValue != nil {
			return String(cacheValue), err
		}
	}
	return
}
*/

func Int64ArrayReplace(sourceArray []int64, from, to int64) (retArray []int64) {
	for _, v := range sourceArray {
		if v == from {
			retArray = append(retArray, to)
		} else {
			retArray = append(retArray, v)
		}
	}
	return
}
